package com.augurit.common.workdayholiday.web;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.util.ExtUtils;
import com.augurit.common.workdayholiday.service.IWhSpecialTimeService;
import com.augurit.common.workdayholiday.web.form.WhSpecialTimeForm;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "wh-special-time.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/common/workdayholiday/SpecialTimeSet.jsp")
})
public class WhSpecialTimeAction extends ExtCrudActionSupport<WhSpecialTimeForm>{

	@Autowired
	private IWhSpecialTimeService whSpecialTimeService;

	private WhSpecialTimeForm form;
	private Long id;
	private Long[] ids;
	private Page<WhSpecialTimeForm> page = new Page<WhSpecialTimeForm>(10);


	/**
	 * 分页查询
	 */
	@Override
	public String list() throws Exception {
		ExtUtils.initPageFromExtGridParam(this.getRequest(), page);
		whSpecialTimeService.search(page, form);
		this.extRenderGridJson(page);
		return null;
	}

	/**
	 * 新增或修改
	 */
	@Override
	public String input() throws Exception {
		this.extRenderFormJson(form);
		return null;
	}

	/**
	 * 保存新增或者修改的Form对象
	 */
	@Override
	public String save() throws Exception {
		whSpecialTimeService.save(form);
		this.extRenderSuccess();
		return null;
	}

	/**
	 * 删除一条获取多条记录
	 */
	@Override
	public String delete() throws Exception {
		whSpecialTimeService.delete(ids);
		return null;
	}
	
	/**
	 * 添加一段非常规工作时间
	 */
	public String addSpecialPeriod() throws Exception{
		whSpecialTimeService.addSpecialPeriod(form.getFrom(), form.getTo(), form.getIsHoliday(), form.getMemo());
		this.extRenderSuccess();
		return null;
	}
	
	/**
	 * 准备页面模型
	 */
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = whSpecialTimeService.get(id);
		}
		else
			form = new WhSpecialTimeForm();
	}
	

	public WhSpecialTimeForm getModel() {
		return form;
	}
	
	// 属性getter和setter方法
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Page<WhSpecialTimeForm> getPage() {
		return page;
	}


	public void setPage(Page<WhSpecialTimeForm> page) {
		this.page = page;
	}

	public Long[] getIds() {
		return ids;
	}

	public void setIds(Long[] ids) {
		this.ids = ids;
	}
	
	
}
